@code-pushup/lighthouse-plugin 0.48.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/plugin-lighthouse/package.json
2
2
  var name = "@code-pushup/lighthouse-plugin";
3
- var version = "0.48.0";
3
+ var version = "0.50.0";
4
4
 
5
5
  // packages/plugin-lighthouse/src/lib/constants.ts
6
6
  import { join } from "node:path";
@@ -676,6 +676,8 @@ var auditResultSchema = scorableWithPluginMetaSchema.merge(
676
676
  );
677
677
  var reportsDiffSchema = z15.object({
678
678
  commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
679
+ portalUrl: urlSchema.optional().describe("Link to comparison page in Code PushUp portal"),
680
+ label: z15.string().optional().describe("Label (e.g. project name)"),
679
681
  categories: makeArraysComparisonSchema(
680
682
  categoryDiffSchema,
681
683
  categoryResultSchema,
@@ -711,11 +713,25 @@ var LIGHTHOUSE_OUTPUT_PATH = join(
711
713
  );
712
714
 
713
715
  // packages/plugin-lighthouse/src/lib/normalize-flags.ts
714
- import chalk9 from "chalk";
716
+ import { bold as bold9, yellow as yellow2 } from "ansis";
717
+
718
+ // packages/utils/src/lib/reports/utils.ts
719
+ import ansis from "ansis";
720
+ import { md } from "build-md";
721
+
722
+ // packages/utils/src/lib/reports/constants.ts
723
+ var TERMINAL_WIDTH = 80;
724
+
725
+ // packages/utils/src/lib/reports/utils.ts
726
+ function formatReportScore(score) {
727
+ const scaledScore = score * 100;
728
+ const roundedScore = Math.round(scaledScore);
729
+ return roundedScore === 100 && score !== 1 ? Math.floor(scaledScore).toString() : roundedScore.toString();
730
+ }
715
731
 
716
732
  // packages/utils/src/lib/file-system.ts
733
+ import { bold, gray } from "ansis";
717
734
  import { bundleRequire } from "bundle-require";
718
- import chalk2 from "chalk";
719
735
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
720
736
 
721
737
  // packages/utils/src/lib/formatting.ts
@@ -760,12 +776,7 @@ function truncateText(text, options) {
760
776
  // packages/utils/src/lib/logging.ts
761
777
  import isaacs_cliui from "@isaacs/cliui";
762
778
  import { cliui } from "@poppinss/cliui";
763
- import chalk from "chalk";
764
-
765
- // packages/utils/src/lib/reports/constants.ts
766
- var TERMINAL_WIDTH = 80;
767
-
768
- // packages/utils/src/lib/logging.ts
779
+ import { underline } from "ansis";
769
780
  var singletonUiInstance;
770
781
  function ui() {
771
782
  if (singletonUiInstance === void 0) {
@@ -817,9 +828,42 @@ async function importModule(options) {
817
828
  return mod;
818
829
  }
819
830
 
831
+ // packages/utils/src/lib/filter.ts
832
+ function filterItemRefsBy(items, refFilterFn) {
833
+ return items.map((item) => ({
834
+ ...item,
835
+ refs: item.refs.filter(refFilterFn)
836
+ })).filter((item) => item.refs.length);
837
+ }
838
+
839
+ // packages/utils/src/lib/git/git.ts
840
+ import { simpleGit } from "simple-git";
841
+
842
+ // packages/utils/src/lib/transform.ts
843
+ function toArray(val) {
844
+ return Array.isArray(val) ? val : [val];
845
+ }
846
+ function capitalize(text) {
847
+ return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
848
+ 1
849
+ )}`;
850
+ }
851
+
852
+ // packages/utils/src/lib/git/git.commits-and-tags.ts
853
+ import { simpleGit as simpleGit2 } from "simple-git";
854
+
855
+ // packages/utils/src/lib/semver.ts
856
+ import { rcompare, valid } from "semver";
857
+
858
+ // packages/utils/src/lib/progress.ts
859
+ import { black, bold as bold2, gray as gray2, green } from "ansis";
860
+ import { MultiProgressBars } from "multi-progress-bars";
861
+
862
+ // packages/utils/src/lib/reports/generate-md-report.ts
863
+ import { MarkdownDocument as MarkdownDocument3, md as md4 } from "build-md";
864
+
820
865
  // packages/utils/src/lib/text-formats/constants.ts
821
866
  var NEW_LINE = "\n";
822
- var TAB = " ";
823
867
 
824
868
  // packages/utils/src/lib/text-formats/html/details.ts
825
869
  function details(title, content, cfg = { open: false }) {
@@ -832,7 +876,7 @@ function details(title, content, cfg = { open: false }) {
832
876
 
833
877
  // packages/utils/src/lib/text-formats/html/font-style.ts
834
878
  var boldElement = "b";
835
- function bold(text) {
879
+ function bold3(text) {
836
880
  return `<${boldElement}>${text}</${boldElement}>`;
837
881
  }
838
882
  var italicElement = "i";
@@ -849,16 +893,6 @@ function link(href, text) {
849
893
  return `<a href="${href}">${text || href}</a>`;
850
894
  }
851
895
 
852
- // packages/utils/src/lib/transform.ts
853
- function toArray(val) {
854
- return Array.isArray(val) ? val : [val];
855
- }
856
- function capitalize(text) {
857
- return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
858
- 1
859
- )}`;
860
- }
861
-
862
896
  // packages/utils/src/lib/text-formats/table.ts
863
897
  function rowToStringArray({ rows, columns = [] }) {
864
898
  if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
@@ -902,51 +936,6 @@ function columnsToStringArray({
902
936
  const cols = columns;
903
937
  return cols.map(({ label, key }) => label ?? capitalize(key));
904
938
  }
905
- function getColumnAlignmentForKeyAndIndex(targetKey, targetIdx, columns = []) {
906
- const column = columns.at(targetIdx) ?? columns.find((col) => col.key === targetKey);
907
- if (typeof column === "string") {
908
- return column;
909
- } else if (typeof column === "object") {
910
- return column.align ?? "center";
911
- } else {
912
- return "center";
913
- }
914
- }
915
- function getColumnAlignmentForIndex(targetIdx, columns = []) {
916
- const column = columns.at(targetIdx);
917
- if (column == null) {
918
- return "center";
919
- } else if (typeof column === "string") {
920
- return column;
921
- } else if (typeof column === "object") {
922
- return column.align ?? "center";
923
- } else {
924
- return "center";
925
- }
926
- }
927
- function getColumnAlignments(tableData) {
928
- const { rows, columns = [] } = tableData;
929
- if (rows.at(0) == null) {
930
- throw new Error("first row can`t be undefined.");
931
- }
932
- if (Array.isArray(rows.at(0))) {
933
- const firstPrimitiveRow = rows.at(0);
934
- return Array.from({ length: firstPrimitiveRow.length }).map(
935
- (_, idx) => getColumnAlignmentForIndex(idx, columns)
936
- );
937
- }
938
- const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
939
- if (columns.length > 0) {
940
- return columns.map(
941
- (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
942
- column.key,
943
- idx,
944
- columns
945
- )
946
- );
947
- }
948
- return Object.keys(biggestRow ?? {}).map((_) => "center");
949
- }
950
939
 
951
940
  // packages/utils/src/lib/text-formats/html/table.ts
952
941
  function wrap(elem, content) {
@@ -969,135 +958,9 @@ function table(tableData) {
969
958
  return wrap("table", `${NEW_LINE}${tableHeaderRow}${tableBody}`);
970
959
  }
971
960
 
972
- // packages/utils/src/lib/text-formats/md/font-style.ts
973
- var boldWrap = "**";
974
- function bold2(text) {
975
- return `${boldWrap}${text}${boldWrap}`;
976
- }
977
- var italicWrap = "_";
978
- function italic2(text) {
979
- return `${italicWrap}${text}${italicWrap}`;
980
- }
981
- var strikeThroughWrap = "~";
982
- function strikeThrough(text) {
983
- return `${strikeThroughWrap}${text}${strikeThroughWrap}`;
984
- }
985
- var codeWrap = "`";
986
- function code2(text) {
987
- return `${codeWrap}${text}${codeWrap}`;
988
- }
989
-
990
- // packages/utils/src/lib/text-formats/md/headline.ts
991
- function headline(text, hierarchy = 1) {
992
- return `${"#".repeat(hierarchy)} ${text}${NEW_LINE}`;
993
- }
994
- function h(text, hierarchy = 1) {
995
- return headline(text, hierarchy);
996
- }
997
- function h1(text) {
998
- return headline(text, 1);
999
- }
1000
- function h2(text) {
1001
- return headline(text, 2);
1002
- }
1003
- function h3(text) {
1004
- return headline(text, 3);
1005
- }
1006
- function h4(text) {
1007
- return headline(text, 4);
1008
- }
1009
- function h5(text) {
1010
- return headline(text, 5);
1011
- }
1012
- function h6(text) {
1013
- return headline(text, 6);
1014
- }
1015
-
1016
- // packages/utils/src/lib/text-formats/md/image.ts
1017
- function image(src, alt) {
1018
- return `![${alt}](${src})`;
1019
- }
1020
-
1021
- // packages/utils/src/lib/text-formats/md/link.ts
1022
- function link2(href, text) {
1023
- return `[${text || href}](${href})`;
1024
- }
1025
-
1026
- // packages/utils/src/lib/text-formats/md/list.ts
1027
- function li(text, order = "unordered") {
1028
- const style = order === "unordered" ? "-" : "- [ ]";
1029
- return `${style} ${text}`;
1030
- }
1031
- function indentation(text, level = 1) {
1032
- return `${TAB.repeat(level)}${text}`;
1033
- }
1034
-
1035
- // packages/utils/src/lib/text-formats/md/paragraphs.ts
1036
- function paragraphs(...sections) {
1037
- return sections.filter(Boolean).join(`${NEW_LINE}${NEW_LINE}`);
1038
- }
1039
-
1040
- // packages/utils/src/lib/text-formats/md/section.ts
1041
- function section(...contents) {
1042
- return `${lines(...contents)}${NEW_LINE}`;
1043
- }
1044
- function lines(...contents) {
1045
- const filteredContent = contents.filter(
1046
- (value) => value != null && value !== "" && value !== false
1047
- );
1048
- return `${filteredContent.join(NEW_LINE)}`;
1049
- }
1050
-
1051
- // packages/utils/src/lib/text-formats/md/table.ts
1052
- var alignString = /* @__PURE__ */ new Map([
1053
- ["left", ":--"],
1054
- ["center", ":--:"],
1055
- ["right", "--:"]
1056
- ]);
1057
- function tableRow(rows) {
1058
- return `|${rows.join("|")}|`;
1059
- }
1060
- function table2(data) {
1061
- if (data.rows.length === 0) {
1062
- throw new Error("Data can't be empty");
1063
- }
1064
- const alignmentRow = getColumnAlignments(data).map(
1065
- (s) => alignString.get(s) ?? String(alignString.get("center"))
1066
- );
1067
- return section(
1068
- `${lines(
1069
- tableRow(columnsToStringArray(data)),
1070
- tableRow(alignmentRow),
1071
- ...rowToStringArray(data).map(tableRow)
1072
- )}`
1073
- );
1074
- }
1075
-
1076
961
  // packages/utils/src/lib/text-formats/index.ts
1077
- var md = {
1078
- bold: bold2,
1079
- italic: italic2,
1080
- strikeThrough,
1081
- code: code2,
1082
- link: link2,
1083
- image,
1084
- headline,
1085
- h,
1086
- h1,
1087
- h2,
1088
- h3,
1089
- h4,
1090
- h5,
1091
- h6,
1092
- indentation,
1093
- lines,
1094
- li,
1095
- section,
1096
- paragraphs,
1097
- table: table2
1098
- };
1099
962
  var html = {
1100
- bold,
963
+ bold: bold3,
1101
964
  italic,
1102
965
  code,
1103
966
  link,
@@ -1105,55 +968,26 @@ var html = {
1105
968
  table
1106
969
  };
1107
970
 
1108
- // packages/utils/src/lib/reports/utils.ts
1109
- var { image: image2, bold: boldMd } = md;
1110
-
1111
- // packages/utils/src/lib/filter.ts
1112
- function filterItemRefsBy(items, refFilterFn) {
1113
- return items.map((item) => ({
1114
- ...item,
1115
- refs: item.refs.filter(refFilterFn)
1116
- })).filter((item) => item.refs.length);
1117
- }
1118
-
1119
- // packages/utils/src/lib/git/git.ts
1120
- import { simpleGit } from "simple-git";
1121
-
1122
- // packages/utils/src/lib/git/git.commits-and-tags.ts
1123
- import { simpleGit as simpleGit2 } from "simple-git";
1124
-
1125
- // packages/utils/src/lib/semver.ts
1126
- import { rcompare, valid } from "semver";
1127
-
1128
- // packages/utils/src/lib/progress.ts
1129
- import chalk3 from "chalk";
1130
- import { MultiProgressBars } from "multi-progress-bars";
1131
-
1132
971
  // packages/utils/src/lib/reports/formatting.ts
1133
- var { headline: headline2, lines: lines2, link: link3, section: section2, table: table3 } = md;
972
+ import {
973
+ MarkdownDocument,
974
+ md as md2
975
+ } from "build-md";
1134
976
 
1135
977
  // packages/utils/src/lib/reports/generate-md-report-categoy-section.ts
1136
- var { link: link4, section: section3, h2: h22, lines: lines3, li: li2, bold: boldMd2, h3: h32, indentation: indentation2 } = md;
1137
-
1138
- // packages/utils/src/lib/reports/generate-md-report.ts
1139
- var { h1: h12, h2: h23, h3: h33, lines: lines4, link: link5, section: section4, code: codeMd } = md;
1140
- var { bold: boldHtml, details: details2 } = html;
978
+ import { MarkdownDocument as MarkdownDocument2, md as md3 } from "build-md";
1141
979
 
1142
980
  // packages/utils/src/lib/reports/generate-md-reports-diff.ts
1143
- var {
1144
- h1: h13,
1145
- h2: h24,
1146
- lines: lines5,
1147
- link: link6,
1148
- bold: boldMd3,
1149
- italic: italicMd,
1150
- table: table4,
1151
- section: section5
1152
- } = md;
1153
- var { details: details3 } = html;
981
+ import {
982
+ MarkdownDocument as MarkdownDocument5,
983
+ md as md6
984
+ } from "build-md";
985
+
986
+ // packages/utils/src/lib/reports/generate-md-reports-diff-utils.ts
987
+ import { MarkdownDocument as MarkdownDocument4, md as md5 } from "build-md";
1154
988
 
1155
989
  // packages/utils/src/lib/reports/log-stdout-summary.ts
1156
- import chalk4 from "chalk";
990
+ import { bold as bold4, cyan, cyanBright, green as green2, red } from "ansis";
1157
991
 
1158
992
  // packages/plugin-lighthouse/src/lib/runner/runner.ts
1159
993
  import { runLighthouse } from "lighthouse/cli/run.js";
@@ -1232,17 +1066,17 @@ var DEFAULT_CLI_FLAGS = {
1232
1066
  };
1233
1067
 
1234
1068
  // packages/plugin-lighthouse/src/lib/runner/utils.ts
1235
- import chalk8 from "chalk";
1069
+ import { bold as bold8 } from "ansis";
1236
1070
  import log from "lighthouse-logger";
1237
1071
  import desktopConfig from "lighthouse/core/config/desktop-config.js";
1238
1072
  import experimentalConfig from "lighthouse/core/config/experimental-config.js";
1239
1073
  import perfConfig from "lighthouse/core/config/perf-config.js";
1240
1074
 
1241
1075
  // packages/plugin-lighthouse/src/lib/runner/details/details.ts
1242
- import chalk7 from "chalk";
1076
+ import { bold as bold7, yellow } from "ansis";
1243
1077
 
1244
1078
  // packages/plugin-lighthouse/src/lib/runner/details/item-value.ts
1245
- import chalk5 from "chalk";
1079
+ import { bold as bold5 } from "ansis";
1246
1080
  function trimSlice(item, maxLength = 0) {
1247
1081
  const str = String(item).trim();
1248
1082
  return maxLength > 0 ? str.slice(0, maxLength) : str;
@@ -1273,8 +1107,8 @@ function formatTableItemPropertyValue(itemValue, itemValueFormat) {
1273
1107
  case "code":
1274
1108
  return html.code(trimSlice(parsedItemValue));
1275
1109
  case "link":
1276
- const link8 = parsedItemValue;
1277
- return html.link(link8.url, link8.text);
1110
+ const link3 = parsedItemValue;
1111
+ return html.link(link3.url, link3.text);
1278
1112
  case "url":
1279
1113
  const url = parsedItemValue;
1280
1114
  return html.link(url);
@@ -1294,12 +1128,10 @@ function formatTableItemPropertyValue(itemValue, itemValueFormat) {
1294
1128
  case "text":
1295
1129
  return truncateText(String(parsedItemValue), 500);
1296
1130
  case "multi":
1297
- ui().logger.info(`Format type ${chalk5.bold("multi")} is not implemented`);
1131
+ ui().logger.info(`Format type ${bold5("multi")} is not implemented`);
1298
1132
  return "";
1299
1133
  case "thumbnail":
1300
- ui().logger.info(
1301
- `Format type ${chalk5.bold("thumbnail")} is not implemented`
1302
- );
1134
+ ui().logger.info(`Format type ${bold5("thumbnail")} is not implemented`);
1303
1135
  return "";
1304
1136
  }
1305
1137
  return itemValue;
@@ -1337,26 +1169,23 @@ function parseTableItemPropertyValue(itemValue) {
1337
1169
  const { url } = objectValue;
1338
1170
  return String(url);
1339
1171
  case "subitems":
1340
- ui().logger.info(
1341
- `Value type ${chalk5.bold("subitems")} is not implemented`
1342
- );
1172
+ ui().logger.info(`Value type ${bold5("subitems")} is not implemented`);
1343
1173
  return "";
1344
1174
  case "debugdata":
1345
- ui().logger.info(
1346
- `Value type ${chalk5.bold("debugdata")} is not implemented`,
1347
- { silent: true }
1348
- );
1175
+ ui().logger.info(`Value type ${bold5("debugdata")} is not implemented`, {
1176
+ silent: true
1177
+ });
1349
1178
  return "";
1350
1179
  }
1351
1180
  return parseSimpleItemValue(objectValue);
1352
1181
  }
1353
1182
 
1354
1183
  // packages/plugin-lighthouse/src/lib/runner/details/utils.ts
1355
- import chalk6 from "chalk";
1184
+ import { bold as bold6 } from "ansis";
1356
1185
  var LighthouseAuditDetailsParsingError = class extends Error {
1357
1186
  constructor(type, rawTable, error) {
1358
1187
  super(
1359
- `Parsing lighthouse report details ${chalk6.bold(
1188
+ `Parsing lighthouse report details ${bold6(
1360
1189
  type
1361
1190
  )} failed:
1362
1191
  Raw data:
@@ -1367,14 +1196,13 @@ ${error}`
1367
1196
  };
1368
1197
 
1369
1198
  // packages/plugin-lighthouse/src/lib/runner/details/table.type.ts
1370
- function parseTableToAuditDetailsTable(details4) {
1371
- const { headings: rawHeadings, items } = details4;
1199
+ function parseTableToAuditDetailsTable(details2) {
1200
+ const { headings: rawHeadings, items } = details2;
1372
1201
  if (items.length === 0) {
1373
1202
  return void 0;
1374
1203
  }
1375
1204
  try {
1376
1205
  return tableSchema().parse({
1377
- title: "Table",
1378
1206
  columns: parseTableColumns(rawHeadings),
1379
1207
  rows: items.map((row) => parseTableRow(row, rawHeadings))
1380
1208
  });
@@ -1413,8 +1241,8 @@ function parseTableEntry([key, value], valueType) {
1413
1241
  }
1414
1242
 
1415
1243
  // packages/plugin-lighthouse/src/lib/runner/details/opportunity.type.ts
1416
- function parseOpportunityToAuditDetailsTable(details4) {
1417
- const { headings: rawHeadings, items } = details4;
1244
+ function parseOpportunityToAuditDetailsTable(details2) {
1245
+ const { headings: rawHeadings, items } = details2;
1418
1246
  if (items.length === 0) {
1419
1247
  return void 0;
1420
1248
  }
@@ -1463,17 +1291,17 @@ function parseOpportunityEntry([key, value], valueType) {
1463
1291
  }
1464
1292
 
1465
1293
  // packages/plugin-lighthouse/src/lib/runner/details/details.ts
1466
- function toAuditDetails(details4) {
1467
- if (details4 == null) {
1294
+ function toAuditDetails(details2) {
1295
+ if (details2 == null) {
1468
1296
  return {};
1469
1297
  }
1470
- const { type } = details4;
1298
+ const { type } = details2;
1471
1299
  switch (type) {
1472
1300
  case "table":
1473
- const table5 = parseTableToAuditDetailsTable(details4);
1474
- return table5 ? { table: table5 } : {};
1301
+ const table2 = parseTableToAuditDetailsTable(details2);
1302
+ return table2 ? { table: table2 } : {};
1475
1303
  case "opportunity":
1476
- const opportunity = parseOpportunityToAuditDetailsTable(details4);
1304
+ const opportunity = parseOpportunityToAuditDetailsTable(details2);
1477
1305
  return opportunity ? { table: opportunity } : {};
1478
1306
  }
1479
1307
  return {};
@@ -1489,16 +1317,16 @@ function logUnsupportedDetails(lhrAudits, { displayCount = 3 } = {}) {
1489
1317
  const slugsWithDetailParsingErrors = [
1490
1318
  ...new Set(
1491
1319
  lhrAudits.filter(
1492
- ({ details: details4 }) => unsupportedDetailTypes.has(details4?.type)
1493
- ).map(({ details: details4 }) => details4?.type)
1320
+ ({ details: details2 }) => unsupportedDetailTypes.has(details2?.type)
1321
+ ).map(({ details: details2 }) => details2?.type)
1494
1322
  )
1495
1323
  ];
1496
1324
  if (slugsWithDetailParsingErrors.length > 0) {
1497
1325
  const postFix = (count) => count > displayCount ? ` and ${count - displayCount} more.` : "";
1498
1326
  ui().logger.debug(
1499
- `${chalk7.yellow("\u26A0")} Plugin ${chalk7.bold(
1327
+ `${yellow("\u26A0")} Plugin ${bold7(
1500
1328
  PLUGIN_SLUG
1501
- )} skipped parsing of unsupported audit details: ${chalk7.bold(
1329
+ )} skipped parsing of unsupported audit details: ${bold7(
1502
1330
  slugsWithDetailParsingErrors.slice(0, displayCount).join(", ")
1503
1331
  )}${postFix(slugsWithDetailParsingErrors.length)}`
1504
1332
  );
@@ -1508,60 +1336,46 @@ function logUnsupportedDetails(lhrAudits, { displayCount = 3 } = {}) {
1508
1336
  // packages/plugin-lighthouse/src/lib/runner/utils.ts
1509
1337
  function normalizeAuditOutputs(auditOutputs, flags = { skipAudits: [] }) {
1510
1338
  const toSkip = new Set(flags.skipAudits ?? []);
1511
- return auditOutputs.filter(({ slug }) => {
1512
- const doSkip = toSkip.has(slug);
1513
- if (doSkip) {
1514
- ui().logger.info(
1515
- `Audit ${chalk8.bold(
1516
- slug
1517
- )} was included in audit outputs of lighthouse but listed under ${chalk8.bold(
1518
- "skipAudits"
1519
- )}.`
1520
- );
1521
- }
1522
- return !doSkip;
1523
- });
1339
+ return auditOutputs.filter(({ slug }) => !toSkip.has(slug));
1524
1340
  }
1525
1341
  var LighthouseAuditParsingError = class extends Error {
1526
1342
  constructor(slug, error) {
1527
- super(
1528
- `
1529
- Audit ${chalk8.bold(slug)} failed parsing details:
1530
- ${error.message}`
1531
- );
1343
+ super(`
1344
+ Audit ${bold8(slug)} failed parsing details:
1345
+ ${error.message}`);
1532
1346
  }
1533
1347
  };
1348
+ function formatBaseAuditOutput(lhrAudit) {
1349
+ const {
1350
+ id: slug,
1351
+ score,
1352
+ numericValue,
1353
+ displayValue,
1354
+ scoreDisplayMode
1355
+ } = lhrAudit;
1356
+ return {
1357
+ slug,
1358
+ score: score ?? 1,
1359
+ value: numericValue ?? score ?? 0,
1360
+ displayValue: displayValue ?? (scoreDisplayMode === "binary" ? score === 1 ? "passed" : "failed" : score ? `${formatReportScore(score)}%` : void 0)
1361
+ };
1362
+ }
1363
+ function processAuditDetails(auditOutput, details2) {
1364
+ try {
1365
+ const parsedDetails = toAuditDetails(details2);
1366
+ return Object.keys(parsedDetails).length > 0 ? { ...auditOutput, details: parsedDetails } : auditOutput;
1367
+ } catch (error) {
1368
+ throw new LighthouseAuditParsingError(auditOutput.slug, error);
1369
+ }
1370
+ }
1534
1371
  function toAuditOutputs(lhrAudits, { verbose = false } = {}) {
1535
1372
  if (verbose) {
1536
1373
  logUnsupportedDetails(lhrAudits);
1537
1374
  }
1538
- return lhrAudits.map(
1539
- ({
1540
- id: slug,
1541
- score,
1542
- numericValue: value = 0,
1543
- // not every audit has a numericValue
1544
- details: details4,
1545
- displayValue
1546
- }) => {
1547
- const auditOutput = {
1548
- slug,
1549
- score: score ?? 1,
1550
- // score can be null
1551
- value,
1552
- displayValue
1553
- };
1554
- if (details4 != null) {
1555
- try {
1556
- const parsedDetails = toAuditDetails(details4);
1557
- return Object.keys(parsedDetails).length > 0 ? { ...auditOutput, details: parsedDetails } : auditOutput;
1558
- } catch (error) {
1559
- throw new LighthouseAuditParsingError(slug, error);
1560
- }
1561
- }
1562
- return auditOutput;
1563
- }
1564
- );
1375
+ return lhrAudits.map((audit) => {
1376
+ const auditOutput = formatBaseAuditOutput(audit);
1377
+ return audit.details == null ? auditOutput : processAuditDetails(auditOutput, audit.details);
1378
+ });
1565
1379
  }
1566
1380
  function determineAndSetLogLevel({
1567
1381
  verbose,
@@ -1673,7 +1487,7 @@ function normalizeFlags(flags) {
1673
1487
  ([flagName]) => !LIGHTHOUSE_UNSUPPORTED_CLI_FLAGS.has(
1674
1488
  flagName
1675
1489
  )
1676
- ).map(([key, v]) => [key === "onlyGroups" ? "onlyCategories" : key, v]).map(([key, v]) => {
1490
+ ).map(([key, v]) => [key === "onlyGroups" ? "onlyCategories" : key, v]).filter(([_, v]) => !(Array.isArray(v) && v.length === 0)).map(([key, v]) => {
1677
1491
  if (!REFINED_STRING_OR_STRING_ARRAY.has(key)) {
1678
1492
  return [key, v];
1679
1493
  }
@@ -1688,9 +1502,9 @@ function logUnsupportedFlagsInUse(flags, displayCount = 3) {
1688
1502
  if (unsupportedFlagsInUse.length > 0) {
1689
1503
  const postFix = (count) => count > displayCount ? ` and ${count - displayCount} more.` : "";
1690
1504
  ui().logger.debug(
1691
- `${chalk9.yellow("\u26A0")} Plugin ${chalk9.bold(
1505
+ `${yellow2("\u26A0")} Plugin ${bold9(
1692
1506
  LIGHTHOUSE_PLUGIN_SLUG
1693
- )} used unsupported flags: ${chalk9.bold(
1507
+ )} used unsupported flags: ${bold9(
1694
1508
  unsupportedFlagsInUse.slice(0, displayCount).join(", ")
1695
1509
  )}${postFix(unsupportedFlagsInUse.length)}`
1696
1510
  );
@@ -1784,12 +1598,7 @@ function filterAuditsAndGroupsByOnlyOptions(audits2, groups, options) {
1784
1598
 
1785
1599
  // packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts
1786
1600
  function lighthousePlugin(url, flags) {
1787
- const {
1788
- skipAudits = [],
1789
- onlyAudits = [],
1790
- onlyCategories: onlyCategories2 = [],
1791
- ...unparsedFlags
1792
- } = normalizeFlags(flags ?? {});
1601
+ const { skipAudits, onlyAudits, onlyCategories: onlyCategories2, ...unparsedFlags } = normalizeFlags(flags ?? {});
1793
1602
  const { audits: audits2, groups } = filterAuditsAndGroupsByOnlyOptions(
1794
1603
  LIGHTHOUSE_NAVIGATION_AUDITS,
1795
1604
  LIGHTHOUSE_GROUPS,
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@code-pushup/lighthouse-plugin",
3
- "version": "0.48.0",
3
+ "version": "0.50.0",
4
4
  "license": "MIT",
5
+ "description": "Code PushUp plugin for measuring web performance and quality with Lighthouse 🔥",
5
6
  "dependencies": {
6
- "@code-pushup/models": "0.48.0",
7
+ "@code-pushup/models": "0.50.0",
8
+ "@code-pushup/utils": "0.50.0",
9
+ "ansis": "^3.3.0",
7
10
  "lighthouse": "^12.0.0",
8
- "@code-pushup/utils": "0.48.0",
9
- "lighthouse-logger": "2.0.1",
10
- "chalk": "^5.3.0"
11
+ "lighthouse-logger": "2.0.1"
11
12
  },
12
- "homepage": "https://github.com/code-pushup/cli#readme",
13
+ "homepage": "https://github.com/code-pushup/cli/tree/main/packages/plugin-lighthouse#readme",
13
14
  "bugs": {
14
15
  "url": "https://github.com/code-pushup/cli/issues"
15
16
  },
@@ -18,33 +19,6 @@
18
19
  "url": "git+https://github.com/code-pushup/cli.git",
19
20
  "directory": "packages/plugin-lighthouse"
20
21
  },
21
- "contributors": [
22
- {
23
- "name": "Igor Katsuba",
24
- "email": "igor@katsuba.dev",
25
- "url": "https://katsuba.dev"
26
- },
27
- {
28
- "name": "Kateřina Pilátová",
29
- "email": "katerina.pilatova@flowup.cz",
30
- "url": "https://github.com/Tlacenka"
31
- },
32
- {
33
- "name": "Matěj Chalk",
34
- "email": "matej.chalk@flowup.cz",
35
- "url": "https://github.com/matejchalk"
36
- },
37
- {
38
- "name": "Michael Hladky",
39
- "email": "michael.hladky@push-based.io",
40
- "url": "https://push-based.io"
41
- },
42
- {
43
- "name": "Michael Seredenko",
44
- "email": "misha.seredenko@push-based.io",
45
- "url": "https://github.com/MishaSeredenkoPushBased"
46
- }
47
- ],
48
22
  "type": "module",
49
23
  "main": "./index.js",
50
24
  "types": "./src/index.d.ts"
package/src/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { lighthousePlugin } from './lib/lighthouse-plugin';
2
2
  export { LIGHTHOUSE_REPORT_NAME } from './lib/runner';
3
3
  export { LIGHTHOUSE_PLUGIN_SLUG, LIGHTHOUSE_OUTPUT_PATH, } from './lib/constants';
4
- export { lighthouseAuditRef, lighthouseGroupRef, LighthouseGroupSlugs, } from './lib/utils';
5
- export { LighthouseOptions } from './lib/types';
4
+ export { lighthouseAuditRef, lighthouseGroupRef, type LighthouseGroupSlugs, } from './lib/utils';
5
+ export type { LighthouseOptions } from './lib/types';
6
6
  export { lighthousePlugin } from './lib/lighthouse-plugin';
7
7
  export default lighthousePlugin;
@@ -1,4 +1,4 @@
1
- import { LighthouseCliFlags } from './runner';
1
+ import { type LighthouseCliFlags } from './runner';
2
2
  import type { LighthouseOptions } from './types';
3
3
  export declare const DEFAULT_LIGHTHOUSE_OPTIONS: {
4
4
  onlyGroups: never[];
@@ -1,7 +1,7 @@
1
1
  import type { FormattedIcu } from 'lighthouse';
2
2
  import type Details from 'lighthouse/types/lhr/audit-details';
3
- import { Result } from 'lighthouse/types/lhr/audit-result';
4
- import { AuditDetails } from '@code-pushup/models';
3
+ import type { Result } from 'lighthouse/types/lhr/audit-result';
4
+ import type { AuditDetails } from '@code-pushup/models';
5
5
  export declare function toAuditDetails<T extends FormattedIcu<Details>>(details: T | undefined): AuditDetails;
6
6
  export declare const unsupportedDetailTypes: Set<string>;
7
7
  export declare function logUnsupportedDetails(lhrAudits: Result[], { displayCount }?: {
@@ -1,5 +1,5 @@
1
1
  import type Details from 'lighthouse/types/lhr/audit-details';
2
- import { Table, TableRowObject } from '@code-pushup/models';
2
+ import { type Table, type TableRowObject } from '@code-pushup/models';
3
3
  export declare function parseOpportunityToAuditDetailsTable(details: Details.Opportunity): Table | undefined;
4
4
  export declare function parseOpportunityItemToTableRow(opportunityItem: Details.OpportunityItem, headings: Details.TableColumnHeading[]): TableRowObject;
5
5
  export declare function parseOpportunityEntry([key, value]: [
@@ -1,5 +1,5 @@
1
1
  import type Details from 'lighthouse/types/lhr/audit-details';
2
- import { Table, TableColumnObject, TableRowObject } from '@code-pushup/models';
2
+ import { type Table, type TableColumnObject, type TableRowObject } from '@code-pushup/models';
3
3
  export declare function parseTableToAuditDetailsTable(details: Details.Table): Table | undefined;
4
4
  export declare function parseTableColumns(rawHeadings: Details.TableColumnHeading[]): TableColumnObject[];
5
5
  export declare function parseTableRow(tableItem: Details.TableItem, headings: Details.TableColumnHeading[]): TableRowObject;
@@ -1,4 +1,4 @@
1
- import Details from 'lighthouse/types/lhr/audit-details';
1
+ import type Details from 'lighthouse/types/lhr/audit-details';
2
2
  export declare class LighthouseAuditDetailsParsingError extends Error {
3
3
  constructor(type: Details['type'], rawTable: Record<string, unknown>, error: string);
4
4
  }
@@ -1,3 +1,3 @@
1
1
  export { createRunnerFunction } from './runner';
2
2
  export { LIGHTHOUSE_REPORT_NAME, LIGHTHOUSE_NAVIGATION_AUDITS, LIGHTHOUSE_GROUPS, DEFAULT_CLI_FLAGS, } from './constants';
3
- export { LighthouseCliFlags } from './types';
3
+ export type { LighthouseCliFlags } from './types';
@@ -1,3 +1,3 @@
1
- import { RunnerFunction } from '@code-pushup/models';
2
- import { LighthouseCliFlags } from './types';
1
+ import type { RunnerFunction } from '@code-pushup/models';
2
+ import type { LighthouseCliFlags } from './types';
3
3
  export declare function createRunnerFunction(urlUnderTest: string, flags?: LighthouseCliFlags): RunnerFunction;
@@ -1,8 +1,8 @@
1
1
  import type { Config } from 'lighthouse';
2
- import { Result } from 'lighthouse/types/lhr/audit-result';
3
- import { AuditOutputs } from '@code-pushup/models';
2
+ import type { Result } from 'lighthouse/types/lhr/audit-result';
3
+ import type { AuditOutputs } from '@code-pushup/models';
4
4
  import type { LighthouseOptions } from '../types';
5
- import { LighthouseCliFlags } from './types';
5
+ import type { LighthouseCliFlags } from './types';
6
6
  export declare function normalizeAuditOutputs(auditOutputs: AuditOutputs, flags?: LighthouseOptions): AuditOutputs;
7
7
  export declare class LighthouseAuditParsingError extends Error {
8
8
  constructor(slug: string, error: Error);
@@ -1,5 +1,5 @@
1
1
  import type { CliFlags } from 'lighthouse';
2
- import { ExcludeNullFromPropertyTypes } from '@code-pushup/utils';
2
+ import type { ExcludeNullFromPropertyTypes } from '@code-pushup/utils';
3
3
  export type LighthouseOptions = ExcludeNullFromPropertyTypes<Partial<Omit<CliFlags, '_' | 'precomputedLanternDataPath' | 'enableErrorReporting' | 'list-all-audits' | 'list-locales' | 'list-trace-categories' | 'chromeIgnoreDefaultFlags' | 'onlyCategories' | 'onlyAudits' | 'skipAudits'>>> & {
4
4
  onlyGroups?: string | string[];
5
5
  onlyAudits?: string | string[];
@@ -1,5 +1,5 @@
1
- import { Audit, CategoryRef, Group } from '@code-pushup/models';
2
- import { LighthouseCliFlags } from './runner';
1
+ import type { Audit, CategoryRef, Group } from '@code-pushup/models';
2
+ import type { LighthouseCliFlags } from './runner';
3
3
  export type LighthouseGroupSlugs = 'performance' | 'accessibility' | 'best-practices' | 'seo' | 'pwa';
4
4
  export declare function lighthouseGroupRef(groupSlug: LighthouseGroupSlugs, weight?: number): CategoryRef;
5
5
  export declare function lighthouseAuditRef(auditSlug: string, weight?: number): CategoryRef;